Uec3.CertifyItemsWindow = Ext.extend(Ext.app.Module, {
	id : 'certifyItems',
	type : 'common/certifyItems',

	/**
	 * Initialize this module. This function is called at startup (page
	 * load/refresh).
	 */
	init : function(initParams) {
	},
	paramsCollection : new Ext.util.MixedCollection(true),

	getParamsByKey : function(key) {

		return this.paramsCollection.get(key);
	},

	getComponents : function(params) {

		var certifyItemsForm;
		var isVisblePanel;
		var middlePanel;
		var market_store;
		var market_combox;
		var componentCertifyItemsInits = function() {

			function showPicture(url,name) {
				
				 Ext.form.Myimg = Ext.extend(Ext.BoxComponent, {     
				        onRender : function(ct, position){     
				            if(!this.el){  		
				                this.el = document.createElement('img');                 
				                this.el.src = this.src;     
				                if(this.forId){     
				                    this.el.setAttribute('htmlFor', this.forId);     
				                }     
				            }     
				           Ext.form.Label.superclass.onRender.call(this, ct, position);     
				       }     
				   });    
				   Ext.reg('myimg', Ext.form.Myimg);  
				 var  Myimg=new Ext.form.Myimg({  
				     width : 120,  
				     height : 150,  
				     src: url
				 }); 			 
				 
				var form=new Ext.form.FormPanel({
				 width : 120,  
				 height : 150,
				 layout:'fit',
				 items:[Myimg]
				 
				 });
		 

				 
				 var win = new Ext.Window({
					 title:name,
					 width:500,
					 region:'center',
					 height:400,
					 iconCls : 'acc-icon',
					 shim : false,
					 animCollapse : false,
					 constrainHeader : true,
					 layout:'fit',
					 maximizable :true,
					 minimizable :true,
					 resizable : true,
					 items:[form]
					 });
				
				
					 win.show();
				
		}
			
			market_store = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({
					url :Uec3.App.Constants.homeUrl+"/market/queryMarket.do"
				}),
				reader : new Ext.data.JsonReader({
							root : 'root',
							fields : [{
										name : 'id'
									}, {
										name : 'name'
									}]
						})
			});
			
		 market_combox = new Ext.form.ComboBox({
				// dataIndex:'relation',
				hiddenName : 'marketId',
				fieldLabel : '市场',
				store : market_store,
				forceSelection : true,
				emptyText : '--请选择市场--',
				mode : 'local',
				width:150,
				anchor:'100%',
				triggerAction : 'all',
				valueField : 'id',
				displayField : 'name',
				loadingText : '加载中...',
				editable : false,
				allowBlank : false,
				blankText : "所在市场不能为空"

			})

			var formReader = new Ext.data.JsonReader(

			{
						root : 'root'
					}, [{
								name : 'id',
								type : 'int'
							}, {
								name : 'marketIds',
								type : 'int'
							},{
								name : 'name',
								type : 'string'
							}, {
								name : 'contactor',
								type : 'string'
							}, {
								name : 'contactorIdentityCode',
								type : 'string'
							}, {
								name : 'code',
								type : 'string'
							}, {
								name : 'business',
								type : 'string'
							}, {
								name : 'taxCode',
								type : 'string'
							}, {
								name : 'gmtCreate',
								type : 'string'
							}, {
								name : 'creatorName',
								type : 'string'
							}, {
								name : 'currentorId',
								type : 'string'
							}, {
								name : 'resultMemo',
								type : 'string'
							},{
								name : 'statusName',
								type : 'string'
							}, {
								name : 'requestRealType',
								type : 'int'
							}, {
								name : 'requestCompanyType',
								type : 'int'
							}, {
								name : 'submitterName',
								type : 'string'
							}, {
								name : 'submitter',
								type : 'string'
							}, {
								name : 'gmtSubmit',
								type : 'string'
							},{
								name : 'contactorIdPath',
								type : 'string'
							},{
								name : 'businessLicensePath',
								type : 'string'
							},{
								name : 'taxCertificationPath',
								type : 'string'
							}]

			);

			isVisblePanel = new Ext.Panel({

						layout : 'form',
						defaults : {
							anchor : '100%',
							msgTarget : 'side'
						},

						items : [
{  xtype : 'panel',
	defaultType : 'textfield',
	layout:'hbox',
	border : false,
	items : [
{
	  xtype:'label',
	  text:'工商注册号:',
	  cls : "x-form-field" 
	  
},
{

		name : 'code',
        width:560,
    readOnly : true,
	style : {
		background : '#dddddd'
	}
}, 
	
    {
		xtype : 'button',
		name : 'businessLicenseFile',
		text : '点击浏览图片',
		width:100,
		buttonCfg : {
			// iconCls : 'icon-photo'
		},
		handler : function(){
			var url = certifyItemsForm.getForm().reader.jsonData.root.taxCertificationPath;
			
			showPicture(url,"营业执照副本复印件");
			
		}
	}
	]
	},

						
								{
		xtype : 'panel',
								defaultType : 'textfield',
								layout:'hbox',
								border : false,
								items : [
{
	  xtype:'label',
	  text:'税号:',
	  cls : "x-form-field" 
},
{

		name : 'taxCode',
        width:560,
	    readOnly : true,
		style : {
			background : '#dddddd'
		}
}, 
								         

                                {
									xtype : 'button',							
									name : 'taxCertificationFile',
									text : '点击浏览图片',
									width:100,
									buttonCfg : {
										// iconCls : 'icon-photo'
									},
									handler : function(){
										
										var url = certifyItemsForm.getForm().reader.jsonData.root.businessLicensePath;
										
										showPicture(url,"税务登记证副本复印件");
									}

								}
								]
								}]
					});

			middlePanel = new Ext.Panel({

				frame : true,
				layout : 'form',
				defaults : {
					msgTarget : 'side'
				},
				bodyStyle : 'padding: 10px 10px 0 10px;',
				items : [{
	
								        xtype:"textfield",
										fieldLabel : '公司名称',
										name : 'name',
										readOnly : true,
										style : {
											background : '#dddddd'
										},
										anchor : '100%',
										allowBlank : false
						}, {
							            xtype:"textfield",
										fieldLabel : '法人名称',
										readOnly : true,
										style :"background :#dddddd;",
										name : 'contactor',
										anchor : '100%',
										allowBlank : false

						}, 
						{  xtype : 'panel',
							defaultType : 'textfield',
							layout:'hbox',
							border : false,
							items : [
							         {
							        	  xtype:'label',
							          	  text:'法人身份证:',
							              cls : "x-form-field" 
							
							         },
							{
								
											name : 'contactorIdentityCode',
						                    width:560,
						        			readOnly : true,
											style : {
												background : '#dddddd'
											}
							}, 
						    {
								xtype : 'button',
								id:"contactorIdentitybutton",
								name : 'contactorIdentitybutton',
								text : '点击浏览图片',
								width:100,
								buttonCfg : {
									// iconCls : 'icon-photo'
								},
								handler : function(){
									
									var url = certifyItemsForm.getForm().reader.jsonData.root.contactorIdPath;
									
									showPicture(url,"身份证复印件");
									
								}
							}
							]
							},

						{

								        xtype:'textfield',
										fieldLabel : '经营项目',
										name : 'business',
										readOnly :true,
										style : {
											background : '#dddddd'
										},
										anchor : '100%'
						},

						{  xtype : 'panel',
							defaultType : 'textfield',
							layout:'hbox',
							border : false,
							items : [{
								xtype : 'label',
								text : '公司类型:',
								style : "margin-top:4px;",
								width : 60,
								cls : "x-form-field" 
							},{
							xtype : 'radiogroup',
							fieldLabel : '公司类型',
							width:450,
							allowBlank : false,
							disabled:true,
							blankText : "必须选择一种公司类型",
							style : "color:#FF8C00;",
							name : 'requestCompanyType',
							items : [{
										boxLabel : "汽修厂/4S店",
										name : "requestCompanyType",
										inputValue : 2,
										checked : true
									}, {
										boxLabel : "经销商",
										name : "requestCompanyType",
										inputValue : 3
									}, {
										boxLabel : "大宗贸易商",
										name : "requestCompanyType",
										inputValue : 4
									}, {
										boxLabel : "汽车配件厂",
										name : "requestCompanyType",
										inputValue : 5
									}, {
										boxLabel : "保险公司",
										name : "requestCompanyType",
										inputValue : 6
									}]
						},{
							xtype : 'label',
							text : '所在市场:',
							style : "margin-top:4px;",
							width : 60,
							cls : "x-form-field" 
						},market_combox ]},isVisblePanel,{
															name : 'resultMemo',
															fieldLabel : '认证结果',
															width:650,
															xtype : 'textarea',
															preventScrollbars : true
														}]

			});

			certifyItemsForm = new Ext.form.FormPanel({
						labelAlign : 'right',
						frame : true,
						//fileUpload : true,
						labelWidth : 60,
						loadingText : '加载数据中...',
						reader : formReader,
						bodyStyle : 'padding: 10px 10px 0 10px;',
						defaults : {
							anchor : '100%',
							msgTarget : 'side'
						},
						buttonAlign : 'center',
						url : '',
						items : [{
									xtype : "hidden",
									fieldLable : "表单ID",
									readOnly : true,
									name : "id"
								},

								{
									xtype : 'radiogroup',
									style : "color:#FF8C00;",
									fieldLabel : '公司认证类型',
									disabled:true,
									blankText : "必须选择一种公司认证类型",
									allowBlank : false,
									name : 'requestRealType',
									items : [{
												boxLabel : "个人认证",
												name : "requestRealType",
												inputValue : 1,
												checked : true
											}, {
												boxLabel : "公司认证",
												name : "requestRealType",
												inputValue : 2
											}]
								}, middlePanel, {
									style : "height:22px;"
								},
								{
									anchor : '100%',
									layout : 'hbox',
									xtype : 'fieldset',
									layoutConfig : {
										padding : '5 0',
										pack : 'start',
										align : 'middle'
									},
									style : 'padding:0px;fontSize:13px;',
									border : false,
									items : [{
												xtype : 'label',
												text : '单据状态:'
											}, {
												xtype : 'textfield',
												width : 100,
												name : 'statusName',
												readOnly : true,
												style : {
													background : '#dddddd',
													width : '55px'
												}
											}, {
												xtype : 'label',
												text : '创建人:',
												width : 60,
												style : {
													marginLeft : '5px',
													width : '48px'
												}
											}, {
												xtype : 'textfield',
												width : 100,
												readOnly : true,
												name : 'creatorName',
												style : {
													background : '#dddddd',
													width : '55px'
												}
											}, {
												xtype : 'label',
												text : '创建时间:',
												width : 60,
												style : {
													marginLeft : '5px',
													width : '61px'
												}
											}, {
												xtype : 'textfield',
												width : 100,
												name : 'gmtCreate',
												format : 'Y-m-d',
												readOnly : true,
												style : {
													marginLeft : '5px',
													background : '#dddddd',
													width : '55px'
												}
											}, {
												xtype : 'label',
												text : '提交人:',
												width : 60,
												style : {
													marginLeft : '5px',
													width : '48px'
												}
											}, {
												xtype : 'textfield',
												width : 100,
												name : 'submitterName',
												readOnly : true,
												style : {
													background : '#dddddd',
													width : '55px'
												}
											}, {
												xtype : 'label',
												text : '提交时间:',
												width : 60,
												style : {
													marginLeft : '5px',
													width : '61px'
												}
											}, {
												xtype : 'textfield',
												width : 100,
												name : 'gmtSubmit',
												readOnly : true,
												style : {
													background : '#dddddd',
													marginLeft : '5px',
													width : '55px'
												}
											}]
								}]
		
			});
       
			// 按钮加载
			function buttonAjaxRequest(statusId, fn) {
				buttonAjax.request({
							url : Uec3.App.Constants.homeUrl
									+ '/certify/queryButtonPanel.do',
							params : {
								statusId : statusId
							},
							success : function(response, options) {
								var result = Ext.decode(response.responseText);
								removeButtons(certifyItemsForm);
								initButtons(result.buttons, operation,
										certifyItemsForm);// 初始按钮
								// 是否遮罩
								// isMark(typeId);
								certifyItemsForm.ownerCt.doLayout();
								if (Ext.isFunction(fn))
									fn(reslut);
							}

						});
			}	
			
			// 按钮操作方法
			var buttonAjax = new Ext.data.Connection();

			var operation = function(btn) {

				eval(btn.func + "(btn)");
			}	
			
		function loadForm(id,statusId){	
		
			// 回显认证信息
			certifyItemsForm.getForm().load({
				url : Uec3.App.Constants.homeUrl + '/certify/queryCertify.do',
				params : {
					certifyId : id
				},
				success : function(form, action) {
                    
					if(form.reader.jsonData.root.status==1){

						buttonAjaxRequest("formalCertify");
						
					}else if(form.reader.jsonData.root.status==2){
						form.findField("resultMemo").setReadOnly(true);							
						buttonAjaxRequest("certifyPass");
						
					}else if(form.reader.jsonData.root.status==3){
						form.findField("resultMemo").setReadOnly(true);
						buttonAjaxRequest("certifyUnpass");
						
					}else{
						

					   	buttonAjaxRequest(statusId);
					   	
					}

				},

				failure : function(form, action) {
                    
				}
			});
		}

		

		
		loadForm(params.id,"formalCertify")
	

			// 关闭认证单据

			function certifyClose(btn) {

			certifyItemsForm.ownerCt.close();

			}

	
			// 认证通过按钮
				
						function certifyPass(){

							market_combox.allowBlank=false;
							
							if (!certifyItemsForm.getForm().isValid()) {

								Ext.Msg.alert("提示", "请填写必须项");

								return;

							}
				
							
							certifyItemsForm.getForm().submit({

								url : Uec3.App.Constants.homeUrl
										+ '/certify/passCertify.do',
								method : "post",
								params : {
									 certifyId : certifyItemsForm.getForm().reader.jsonData.root.id
								},
								waitMsg : '认证成功,请稍后...',
								success : function(form, action) {
									
								       loadForm(form.reader.jsonData.root.id,"certifyPass");
								       params.certify_ds.reload();
																	
								},
								failure : function(form, action) {

									Ext.Msg.alert("错误", "认证单据失败");
								}
							});
							
				
							
					}
			// 认证不通过按钮
						
						function certifyUnpass(){

							market_combox.allowBlank=true;
												
							if (!certifyItemsForm.getForm().isValid()) {

								Ext.Msg.alert("提示", "请填写必须项");

								return;

							}
							
							certifyItemsForm.getForm().submit({
								
								url : Uec3.App.Constants.homeUrl
										+ '/certify/unpassCertify.do',
								method : "post",
								waitMsg : '认证失败...',
								params : {
								   certifyId : certifyItemsForm.getForm().reader.jsonData.root.id
								},
								success : function(form, action) {
									
								     loadForm(form.reader.jsonData.root.id,"certifyUnpass");
								     params.certify_ds.reload();
								     
								},
								failure : function(form, action) {

									Ext.Msg.alert("错误", "认证单据失败");
								}
							});
				
						}
		

		}

		function certifyItemsControlEvent() {

			certifyItemsForm.getForm().on("actioncomplete",
					function(form, action) {
				market_combox.setRawValue('');				
				var rootElement = form.reader.jsonData.root;
				var rt = rootElement.requestRealType;
			//	certifyItemsForm.getForm().findField("marketId").allowBlank=false;
				if(rt==2){
					certifyItemsForm.ownerCt.setHeight(475);
					isVisblePanel.show();
				}else{
					certifyItemsForm.ownerCt.setHeight(420);
					isVisblePanel.hide();
				}

					market_store.load({params:{queryParam:rootElement.requestCompanyType},callback:function(){
					var record = market_combox.findRecord(market_combox.valueField, rootElement.marketIds);	
					if(record){
					  var text=record.get(market_combox.displayField);

					  market_combox.setRawValue(text);	
					  
					   market_combox.setReadOnly(true);
					}
					
				}})



					})
		}

		componentCertifyItemsInits();
		certifyItemsControlEvent();
		return certifyItemsForm;
	},

	/**
	 * Create this modules window here.
	 */
	createWindow : function(params) {
		var windowId = 'certifyItems';
		var module=this;
		if (params) {
			windowId += "_" + params.winId;
		}
		var desktop = Uec3.App.getDesktop();
		var win = desktop.getWindow(windowId);
		if (!win) {
			win = desktop.createWindow({
						id : windowId,
						title : '认证明细',
						width :850,
						height : 420,
						iconCls : 'acc-icon',
						shim : false,
						animCollapse : false,
						constrainHeader : true,
						maximizable : false,
						resizable : true,
						listeners:{"beforeshow":function(){
							
						}
			},
						taskbuttonTooltip : "认证明细",
						layout : "fit",
						tools : [{
									id : 'refresh',
									handler : Ext.emptyFn,
									scope : this
								}],
						items : [this.getComponents(params)]
					});
					
		}
		win.show();
	}
});